using Admin2025.Application.Events;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Admin2025.Application.EventHandlers;

//用户创建事件处理器 - 记录审计日志
public class UserCreatedAuditHandler : INotificationHandler<UserCreatedNotification>
{
    private readonly ILogger<UserCreatedAuditHandler> _logger;
    public UserCreatedAuditHandler(ILogger<UserCreatedAuditHandler> logger)
    {
        _logger = logger;
    }

    public async Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
    {
        var userEvent = notification.UserCreatedEvent;

        _logger.LogInformation("用户创建审计：事件ID={Event},用户ID={UserId},用户名={Username}，昵称={Nickname}，创建时间={OccurredOn}",
            userEvent.EventId,
            userEvent.UserId,
            userEvent.Username,
            userEvent.Nickname,
            userEvent.OccurredOn
        );
        //这里可以记录到审计日志表
        await Task.CompletedTask;
    }
}